<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.0.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/hexo/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/hexo/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/hexo/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/hexo/images/logo.svg" color="#222">

<link rel="stylesheet" href="/hexo/css/main.css">


<link rel="stylesheet" href="/hexo/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"hf98.gitee.io","root":"/hexo/","scheme":"Pisces","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="STP起因企业为了提高链路的可靠性，采用了冗余链路，但冗余链路会导致产生环路 1. 问题 广播风暴交换机转发采用flood(泛洪)，当形成环路时会引起广播风暴，终端会频繁收到相同数据包，同时由于海量的数据包会导致交换机瘫痪。  mac地址震荡由于产生环路，广播风暴会导致交换机中mac地址震荡，在不同接口上反复变更。 2. STP特性及工作流程 特性  消除环路 通过阻断冗余链路来消除网络中可能存在">
<meta property="og:type" content="article">
<meta property="og:title" content="STP">
<meta property="og:url" content="http://hf98.gitee.io/hexo/2020/07/05/na/%E7%AD%96%E7%95%A5/STP/">
<meta property="og:site_name" content="梁汉烽的博客">
<meta property="og:description" content="STP起因企业为了提高链路的可靠性，采用了冗余链路，但冗余链路会导致产生环路 1. 问题 广播风暴交换机转发采用flood(泛洪)，当形成环路时会引起广播风暴，终端会频繁收到相同数据包，同时由于海量的数据包会导致交换机瘫痪。  mac地址震荡由于产生环路，广播风暴会导致交换机中mac地址震荡，在不同接口上反复变更。 2. STP特性及工作流程 特性  消除环路 通过阻断冗余链路来消除网络中可能存在">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-07-04T16:00:00.000Z">
<meta property="article:modified_time" content="2020-08-10T06:38:23.794Z">
<meta property="article:author" content="Liang HF">
<meta property="article:tag" content="网络">
<meta property="article:tag" content="扩展知识">
<meta property="article:tag" content="路由协议">
<meta property="article:tag" content="STP">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://hf98.gitee.io/hexo/2020/07/05/na/%E7%AD%96%E7%95%A5/STP/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>STP | 梁汉烽的博客</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/hexo/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">梁汉烽的博客</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">日常学习总结</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/hexo/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/hexo/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/hexo/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/hexo/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://hf98.gitee.io/hexo/2020/07/05/na/%E7%AD%96%E7%95%A5/STP/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo/images/avatar.gif">
      <meta itemprop="name" content="Liang HF">
      <meta itemprop="description" content="普通人">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="梁汉烽的博客">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          STP
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-07-05 00:00:00" itemprop="dateCreated datePublished" datetime="2020-07-05T00:00:00+08:00">2020-07-05</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-08-10 14:38:23" itemprop="dateModified" datetime="2020-08-10T14:38:23+08:00">2020-08-10</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/hexo/categories/%E8%B7%AF%E7%94%B1%E4%BA%A4%E6%8D%A2/" itemprop="url" rel="index"><span itemprop="name">路由交换</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="STP"><a href="#STP" class="headerlink" title="STP"></a>STP</h2><h3 id="起因"><a href="#起因" class="headerlink" title="起因"></a>起因</h3><p>企业为了提高链路的可靠性，采用了冗余链路，但冗余链路会导致产生环路</p>
<h3 id="1-问题"><a href="#1-问题" class="headerlink" title="1. 问题"></a>1. 问题</h3><ol>
<li><p>广播风暴<br>交换机转发采用flood(泛洪)，当形成环路时会引起广播风暴，终端会频繁收到相同数据包，同时由于海量的数据包会导致交换机瘫痪。</p>
</li>
<li><p>mac地址震荡<br>由于产生环路，广播风暴会导致交换机中mac地址震荡，在不同接口上反复变更。</p>
<h3 id="2-STP特性及工作流程"><a href="#2-STP特性及工作流程" class="headerlink" title="2. STP特性及工作流程"></a>2. STP特性及工作流程</h3><p> 特性</p>
<ol>
<li><p>消除环路 通过阻断冗余链路来消除网络中可能存在的环路</p>
</li>
<li><p>链路备份 当活动路径发生故障时，激活备份链路，恢复网络连通性</p>
<p>工作流程</p>
</li>
<li><p>选举一台根桥<br>  每台交换机启动后，均广播BPDU，其中根桥均为自己，经过一轮交换后，BID较小的成为root(先比较优先级，再比较mac地址)</p>
</li>
<li><p>选举一个根端口（非根桥/最小链路开销）<br>  非根交换机在选举根端口时分别依据该端口的根路径开销、对端BID、对端PID和本端PID选举出根端口</p>
</li>
<li><p>选举指定端口<br>  在每条二层链路上选举指定端口转发，选举依据顺序为根路径开销，BID，PID</p>
</li>
<li><p>阻塞剩余端口<br>  阻塞所有未指定的端口，转发端口为线数*2-阻塞端口</p>
<h3 id="3-bridge-protocol-data-unit协议数据单元"><a href="#3-bridge-protocol-data-unit协议数据单元" class="headerlink" title="3.bridge protocol data unit协议数据单元"></a>3.bridge protocol data unit协议数据单元</h3></li>
</ol>
</li>
<li><p>协议端口号 组播01-80-c2-00-00-00</p>
</li>
<li><p>BPDU数据结构</p>
<pre><code> PID：protocol ID 协议ID
 PVI：protocol version id 协议细分类型
 type :数据包类型
 flags：包的各种标志
 rootID:发送配置BPDU的根桥交换机的标识
 path cost:用于衡量路径的优劣，越低越优先，根据端口速率判断链路开销大小
 root path cost：从发送BPDU的交换机到达根交换机的最短路径总开销
     根据路径开销计算到达根桥的最短路径
 bridge id：发送该BPDU的交换机的标识
     用于唯一标识一个交换机 ,由优先级与mac地址组成
     优先级默认32768 取值范围0~65535
 port id：发送此BPDU的交换机端口的端口标识
     用于标识一个交换机上的端口 ,由优先级与端口编号组成
     优先级默认128 取值范围0~255</code></pre>
</li>
<li><p>BPDU类型</p>
<pre><code> 1. 配置类BPDU configuration
     选举根交换机以及决定每个交换机端口的角色和状态
     初始化过程中，每个桥都主动发送配置BPDU
     选举稳定/网络拓扑稳定后，只有根网桥主动发送配置BPDU，其他交换机收到后才发送自己的配置BPDU
     发送周期为Hello Time 默认为2S
     老化时间为MAX Age    默认为10S
 2. 拓扑变更通告 topology change notification
     下游交换机感知到拓扑发生变化向上游发送的拓扑变化通知</code></pre>
<h3 id="4-端口状态及计时常量"><a href="#4-端口状态及计时常量" class="headerlink" title="4.端口状态及计时常量"></a>4.端口状态及计时常量</h3><p> 端口状态</p>
<pre><code> disabled：稳定，端口关闭 不接收处理BPDU
 blocking:      接收BPDU，不转发BPDU，阻塞端口 
 listening：接收转发BPDU，监听拓扑变化
 learning:    接收转发BPDU，学习mac
 forwarding: 链路状态稳定，接受转发BPDU，学习mac并转发数据</code></pre>
<p> 计时常量</p>
<pre><code> hello：根桥发送BPDU的间隔 2S
 forward delay：监听和学习的持续时间 15S
 Max age：保持阻塞的最大时间 20S</code></pre>
<h3 id="5-STP命令配置"><a href="#5-STP命令配置" class="headerlink" title="5. STP命令配置"></a>5. STP命令配置</h3><p> 1.系统模式<br> stp mode {mstp|stp|rstp} 配置STP模式，缺省为MSTP<br> stp priority {priority} 配置BID优先级 0~61440 步长4096<br> stp root {primary|secondary} 自动修改优先级，指定主/备根桥<br> stp pathcost-standard {protocol} 配置路径开销值的标准<br> stp cost {cost} 修改STP开销<br> stp port priority {priority} 修改PID优先级 步长为16<br> dis stp [brief] 显示STP配置信息</p>
</li>
</ol>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/hexo/tags/%E7%BD%91%E7%BB%9C/" rel="tag"># 网络</a>
              <a href="/hexo/tags/%E6%89%A9%E5%B1%95%E7%9F%A5%E8%AF%86/" rel="tag"># 扩展知识</a>
              <a href="/hexo/tags/%E8%B7%AF%E7%94%B1%E5%8D%8F%E8%AE%AE/" rel="tag"># 路由协议</a>
              <a href="/hexo/tags/STP/" rel="tag"># STP</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/hexo/2020/07/05/na/%E8%B7%AF%E7%94%B1/RIP/" rel="prev" title="RIP">
      <i class="fa fa-chevron-left"></i> RIP
    </a></div>
      <div class="post-nav-item">
    <a href="/hexo/2020/07/05/na/%E7%AD%96%E7%95%A5/ACL/" rel="next" title="ACL">
      ACL <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#STP"><span class="nav-number">1.</span> <span class="nav-text">STP</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%B5%B7%E5%9B%A0"><span class="nav-number">1.1.</span> <span class="nav-text">起因</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-%E9%97%AE%E9%A2%98"><span class="nav-number">1.2.</span> <span class="nav-text">1. 问题</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-STP%E7%89%B9%E6%80%A7%E5%8F%8A%E5%B7%A5%E4%BD%9C%E6%B5%81%E7%A8%8B"><span class="nav-number">1.3.</span> <span class="nav-text">2. STP特性及工作流程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-bridge-protocol-data-unit%E5%8D%8F%E8%AE%AE%E6%95%B0%E6%8D%AE%E5%8D%95%E5%85%83"><span class="nav-number">1.4.</span> <span class="nav-text">3.bridge protocol data unit协议数据单元</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-%E7%AB%AF%E5%8F%A3%E7%8A%B6%E6%80%81%E5%8F%8A%E8%AE%A1%E6%97%B6%E5%B8%B8%E9%87%8F"><span class="nav-number">1.5.</span> <span class="nav-text">4.端口状态及计时常量</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-STP%E5%91%BD%E4%BB%A4%E9%85%8D%E7%BD%AE"><span class="nav-number">1.6.</span> <span class="nav-text">5. STP命令配置</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">Liang HF</p>
  <div class="site-description" itemprop="description">普通人</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/hexo/archives/">
        
          <span class="site-state-item-count">15</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/hexo/categories/">
          
        <span class="site-state-item-count">2</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/hexo/tags/">
          
        <span class="site-state-item-count">15</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Liang HF</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://pisces.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/hexo/lib/anime.min.js"></script>
  <script src="/hexo/lib/velocity/velocity.min.js"></script>
  <script src="/hexo/lib/velocity/velocity.ui.min.js"></script>

<script src="/hexo/js/utils.js"></script>

<script src="/hexo/js/motion.js"></script>


<script src="/hexo/js/schemes/pisces.js"></script>


<script src="/hexo/js/next-boot.js"></script>




  















  

  

</body>
</html>
